﻿import { I{{ModelClassName}} } from "@/models/{{ModelClassName}}";
import * as {{ModelClassName}}Service from "@/services/{{ModelClassName}}Service";

export const Set_{{ModelClassName}}_List :string = "Set_{{ModelClassName}}_List";

interface I{{ModelClassName}}Entity {
  {{ModelClassName}}?: Array<I{{ModelClassName}}>;
  count: number;
}

export interface IState {
  {{ModelClassName}}: I{{ModelClassName}}Entity;
}

const state = (): IState => ({
  {{ModelClassName}}: {
    {{ModelClassName}}: [],
    count: 0,
  },
});

const mutations: { [key: string]: Function } = {
  [Set_{{ModelClassName}}_List](state: IState, payload: { [key: string]: any }) {
    state.{{ModelClassName}}.{{ModelClassName}} = payload.data;
    state.{{ModelClassName}}.count = payload.count;
  },

  /** 删除数据 */
 deleteDataById(state: IState, id: number| string) {
     state.{{ModelClassName}}.{{ModelClassName}}=state.{{ModelClassName}}.{{ModelClassName}}?.filter(x=>x.id!==id);
},

};

const getters: { [key: string]: Function } = {};

const actions = {
  /** 列表查询 */
  getPageList({ commit }: any, params: { [key: string]: any }) {
    {{ModelClassName}}Service.getPageList(params).subscribe((res) => {
      commit(Set_{{ModelClassName}}_List, res);
    });
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters,
};
